/*
 * This program is free software; you can redistribute it and/or modify it under the 
 * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software 
 * Foundation.
 *
 * You should have received a copy of the GNU Lesser General Public License along with this 
 * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html 
 * or from the Free Software Foundation, Inc., 
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 
 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 * See the GNU Lesser General Public License for more details.
 *
 * Copyright 2008 Pentaho Corporation.  All rights reserved.
 *
 * @author Will Gorman (wgorman@pentaho.com)
 */
package org.pentaho.actioneditor.client.util;

import com.google.gwt.user.client.Command;
import com.google.gwt.user.client.ui.MenuBar;
import com.google.gwt.user.client.ui.MenuItem;

public class ActionParameterMenu extends MenuBar {
  
  public static interface ItemCommand {
    public void execute(String text);
  }
  
  public ItemCommand itemCommand; 
  
  public ActionParameterMenu() {
    super();
    MenuItem selections = new MenuItem("\\/", (Command)null);
    MenuBar selectionMenu = new MenuBar(true);
    selectionMenu.addItem("input1", new Command() {public void execute() {handleSelection("input1");}});
    selectionMenu.addItem("input2", new Command() {public void execute() {handleSelection("input2");}});
    selectionMenu.addItem("input3", new Command() {public void execute() {handleSelection("input3");}});
    selections.setSubMenu(selectionMenu);
    this.addItem(selections);
  }
  
  public void setItemCommand(ItemCommand itemCommand) {
    this.itemCommand = itemCommand;
  }
  
  public void handleSelection(String selection) {
    System.out.println("selection clicked: " + selection);
    if (itemCommand != null) {
      itemCommand.execute(selection);
    }
  }
}
